package com.Sdebruijn.curriculumvitae.swipey;

import android.app.Activity;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.Sdebruijn.curriculumvitae.R;

/**
 * Adapter to fill the {@link SwipeyTabs} from the info screen.
 */
public class SwipeyTabsAdapter implements SwipeyTabsAdapterBase {

	/** The context. */
	private final Activity context;

	/** The titles. */
	private final String[] titles;

	/** The inflater. */
	private final LayoutInflater inflater;

	/** The view pager. */
	private final ViewPager viewPager;

	/**
	 * Instantiates a new swipey tabs adapter.
	 * 
	 * @param ctx
	 *            the ctx
	 * @param titles
	 *            the titles
	 */
	public SwipeyTabsAdapter(final Activity ctx, final String[] titles,
			final ViewPager viewPager) {
		this.context = ctx;
		this.titles = titles;
		this.viewPager = viewPager;
		inflater = LayoutInflater.from(context);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.gemoro.dopharma.adapters.TabsAdapter#getView(int)
	 */
	@Override
	public View getView(final int position) {
		TextView tab = (TextView) inflater.inflate(R.layout.tab_swipey, null);

		tab.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(final View v) {
				viewPager.setCurrentItem(position);
			}
		});

		if (position < titles.length) {
			tab.setText(titles[position]);
		}

		return tab;
	}

	@Override
	public int getCount() {
		return titles.length;
	}
}
